#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=AionClient.ico
#AutoIt3Wrapper_outfile=AionLauncher.exe
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

If _Singleton(@ScriptName, 1) = 0 Then
	MsgBox(0,"","이미 프로그램이 실행중입니다.")
	Exit
EndIf

;ini
Global $ini = @ScriptDir & "\AionLauncher.ini"
Global $ServerSite = "about:Tabs"
Global $Version = "1.5.1.2"
Global $OS = "x86"

#Region ### START Koda GUI section ### Form=C:\Users\㈜RaGEZONE\Documents\오토잇\뉴런처\런처.kxf
$Form = GUICreate("Aion Launcher " & $OS & " v" & $Version, 314, 408, 675, 226)
GUISetFont(9, 400, 0, "맑은 고딕")

;====== 탭 박스 시작
$TabConfig = GUICtrlCreateTab(16, 148, 281, 233)

;====== 탭1번 서버배율
GUICtrlCreateTabItem("서버배율")
$Obj = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($Obj, 16, 172, 280, 210)
if FileExists($ini) Then
	$ServerSite = IniRead($ini, "Server", "Site", "")
EndIf
$Obj.navigate($ServerSite)

;====== 탭2번 환경설정
$TapConfig = GUICtrlCreateTabItem("환경설정")
;====== 로그인구룹
GUICtrlCreateGroup(" Login Setting ", 24, 176, 193, 81)
GUICtrlCreateLabel("Account", 32, 200, 44, 17)
GUICtrlCreateLabel("Password", 32, 224, 50, 17)
$InputAccount = GUICtrlCreateInput("", 88, 200, 121, 21)
$InputPassword = GUICtrlCreateInput("", 88, 224, 121, 21)
;====== 서버설정구룹
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup(" Server Setting ", 24, 264, 193, 81)
GUICtrlCreateLabel("ServerIP", 32, 288, 45, 17)
GUICtrlCreateLabel("Bin32DIR", 32, 312, 50, 17)
$InputServerIP = GUICtrlCreateInput("", 88, 288, 121, 21)
$InputBin32DIR = GUICtrlCreateInput("", 88, 312, 121, 21)

;====== 로그인아이티 비밀번호 저장
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Save = GUICtrlCreateButton("Save", 224, 184, 59, 161)
GUICtrlSetFont(-1, 9, 800, 0, "맑은 고딕")

$iniLabel = GUICtrlCreateLabel("", 64, 360, 164, 17)
GUICtrlSetFont(-1, 9, 400, 0, "맑은 고딕")

$Checkbox = GUICtrlCreateCheckbox("Aion Start 후 런처 유지", 26, 355, 200, 17)
GUICtrlSetFont(-1, 9, 400, 0, "맑은 고딕")
;====== 탭2번 끝

;====== 탭3번
GUICtrlCreateTabItem("About")
 GUICtrlCreateLabel("※ Aion Launcher", 32, 184, 109, 21)
GUICtrlSetFont(-1, 10, 800, 0, "맑은 고딕")
GUICtrlCreateLabel("01. 2012-01-19 v1.0.0.0", 40, 208, 138, 19)
GUICtrlSetFont(-1, 9, 400, 0, "맑은 고딕")
GUICtrlCreateLabel("02. 2012-01-20 v1.5.1.2", 40, 227, 138, 19)
GUICtrlSetFont(-1, 9, 400, 0, "맑은 고딕")

GUICtrlCreateTabItem("")
;====== 탭 박스 끝

;====== 타이틀
GUICtrlCreateLabel("Aion Launcher", 56, 11, 234, 25)
GUICtrlSetFont(-1, 12, 800, 0, "맑은 고딕")
;====== 게임실행
$Start = GUICtrlCreateButton("Aion Start", 16, 48, 283, 89)
GUICtrlSetFont(-1, 20, 800, 0, "맑은 고딕")
GUICtrlCreateIcon("AionClient.ico", -1, 16, 8, 32, 32)
GUICtrlCreateLabel("Copyright ⓒ by Ezya To Taro", 80, 384, 162, 19)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

		Case $TabConfig
			TapCheck()

		Case $Save
			;======== ini 파일 쓰기 부분 =================================
			$Account = GUICtrlRead($InputAccount)
			$Password = GUICtrlRead($InputPassword)

			If $Account = "" Then
				If $Password = "" Then
					MsgBox(0, "", "Account와 Password를 입력하세요.")
					GUICtrlSetState($InputAccount, $GUI_FOCUS)
				EndIf
			EndIf

			If $Account = "" Then
				If $Password Then
					MsgBox(0, "", "Account를 입력하세요.")
					GUICtrlSetState($InputAccount, $GUI_FOCUS)
				EndIf
			EndIf

			If $Account Then
				If $Password = "" Then
					MsgBox(0, "", "Password를 입력하세요.")
					GUICtrlSetState($InputPassword, $GUI_FOCUS)
				EndIf
			EndIf

			If $Password Then
				If $Account Then
					$CloseCheck = GUICtrlRead($Checkbox)
					If $CloseCheck = 1 Then
						$LauncherKeep = "true"
					Else
						$LauncherKeep = "false"
					EndIf

					$ServerIP = GUICtrlRead($InputServerIP)
					$Bin32DIR = GUICtrlRead($InputBin32DIR)

					IniWrite($ini, "Login", 'Account', $Account)
					IniWrite($ini, "Login", 'Password', $Password)
					IniWrite($ini, "Server", 'ServerIP', $ServerIP)
					IniWrite($ini, "Server", 'Bin32DIR', $Bin32DIR)
					IniWrite($ini, "Server", 'Site', $ServerSite)
					IniWrite($ini, "Launcher", 'Keep', $LauncherKeep)
					;GUICtrlSetData($iniLabel, "Created AionLauncher.ini")
					MsgBox(0, "", "환경설정이 왼료되었습니다.")
				EndIf
			EndIf

		Case $Start
			if FileExists($ini) Then
				$Account = IniRead($ini, "Login", "Account", "")
				$Password = IniRead($ini, "Login", "Password", "")
				$ServerIP = IniRead($ini, "Server", "ServerIP", "")
				$Bin32DIR = IniRead($ini, "Server", "Bin32DIR", "")
				$LauncherKeep = IniRead($ini, "Launcher", "Keep", "")
				Run( $Bin32DIR & "\aion.bin -ip:" & $ServerIP & " -port:2106 -noauthgg -cc:0 -lang:kor -account:" & $Account & " -password:" & $Password & " -ingameshop -noauthgg -ls -charnamemenu -ncg -noweb")
				if $LauncherKeep = "false" Then
					Exit
				EndIf
			Else
				MsgBox(0, "", "환경설정을 하세요.")
				GUICtrlSetState($TapConfig, $GUI_SHOW)
				GUICtrlSetState($InputAccount, $GUI_FOCUS)
				TapCheck()
			EndIf
	EndSwitch
WEnd


#cs
	-----------------------------------------------------------
	텝체크
#ce
Func TapCheck()
	$TapIndex = GUICtrlRead($TabConfig)
	If $TapIndex = 1 Then
		if FileExists($ini) Then
			$Account = IniRead($ini, "Login", "Account", "")
			$Password = IniRead($ini, "Login", "Password", "")
			$ServerIP = IniRead($ini, "Server", "ServerIP", "")
			$Bin32DIR = IniRead($ini, "Server", "Bin32DIR", "")
			$LauncherKeep = IniRead($ini, "Launcher", "Keep", "")
			if $LauncherKeep = "true" Then
				GUICtrlSetState($Checkbox, $GUI_CHECKED)
			EndIf
		Else
			$Account = ""
			$Password = ""
			$ServerIP = "127.0.0.1"
			$Bin32DIR = "bin32"
		EndIf
		GUICtrlSetData($InputAccount, $Account)
		GUICtrlSetData($InputPassword, $Password)
		GUICtrlSetData($InputServerIP, $ServerIP)
		GUICtrlSetData($InputBin32DIR, $Bin32DIR)
	EndIf
EndFunc